$(function(){
	 changeColor();
	var down="img/down.png";
	var up="img/up.png";
	var arrow="img/arrow.png";
	var arrows="img/arrows.png";
	hideInformation($('#arrow'),$("#arrow img"),$(".effect"),arrow,arrows)
	hideInformation($('.arrowTwo'),$(".arrowTwo img"),$(".effectTwo"),arrow,arrows)
	hideInformation($('.arrowThree'),$(".arrowThree img"),$(".effectThree"),arrow,arrows)
	hideInformation($('.arrowFour'),$(".arrowFour img"),$(".effectFour"),arrow,arrows)
	hideInformation($('.arrowFive'),$(".arrowFive img"),$(".effectFive"),arrow,arrows)
	hideInformation($('.jyName'),$(".jyName img"),$(".mineInfo"),arrow,arrows)
	hidePeople()
	addLoan()
	cancle()
	dateFocus()
	submitBack()
	edit()
	timeCancle()
	cancleAmend()
	tabs()
	requireInfo()
	upLoad()
	mustUpLoad()
	otherUpLoad();
	delFile()
	changeCInfo()
	//日志
	blog();
	//修改信息(数据)
	correctInfo();
	sshow();
	
	window.comms=new Array();
	//window.xhNumber=new Array();
	//for(var i=0;i<20;i++){
	//	xhNumber.push("");
		//console.log(xhNumber.length);
	//}
	//放款金额
	var loanMoneys=0;
	//供应商
	var suppliers=0;
	//用途
	var purpuses=0;
	//累计放款
	var totalMoney=0;
	
	//已付款(我总共给供应商)
	var sumPurpuse=0;
	
	//添加放款
	
	fkShow(".fkup",".fkShow");
	fkShow(".givePlan",".addMake");
	fkShow(".givePlanTwo",".addMake1");
	fkShow(".givePlanThree",".addMake2");
	fkShow(".addPayimgOne",".addpayInfoOne");
	fkShow(".addPayimgTwo",".addpayInfoTwo");
	fkShow(".addPayimgThree",".addpayInfoThree");
	addSloan();
	//合同付款管理
	supplier();
	var use1=use2=use3=use4=0;
	var use5=use6=use7=use8=0;
	var use9=use10=use11=use12=0;
	//还款计划分几笔还完
	var give1=give2=give3=give4=0;
	var give5=give6=give7=give8=0;
	var give9=give10=give11=give12=0;
	
	
	//放款用途第1笔到第4笔
	oneToFour(".addUsesOne",".addMake",".use1",".use2",".use3",".use4",use1,use2,use3,use4,"1","2","3","4");
	//放款用途第5笔到第8笔
	oneToFour(".addUsesTwo",".addMake1",".use5",".use6",".use7",".use8",use5,use6,use7,use8,"5","6","7","8");
	//放款用途第9笔到第12笔
	oneToFour(".addUsesThree",".addMake2",".use9",".use10",".use11",".use12",use9,use10,use11,use12,"9","10","11","12");
	//添加放款表格第1笔到第4笔
	loanDetail($(".addMake .table tbody"))
	//添加放款表格第5笔到第8笔
	loanDetail($(".addMake1 .table tbody"))
	//添加放款表格第9笔到第12笔
	loanDetail($(".addMake2 .table tbody"))
	 
	//添加还款计划表格
	loanDetail($(".addpayInfoOne .table tbody"))
	loanDetail($(".addpayInfoTwo .table tbody"))
	loanDetail($(".addpayInfoThree .table tbody"))
	
	
	//提交还款计划
	subgivePlan(".payingBtnOne","1","2","3","4",give1,give2,give3,give4,".addpayInfoOne",".givemoney1",".givemoney2",".givemoney3",".givemoney4");
	subgivePlan(".payingBtnTwo","5","6","7","8",give5,give6,give7,give8,".addpayInfoTwo",".givemoney5",".givemoney6",".givemoney7",".givemoney8");
	subgivePlan(".payingBtnThree","9","10","11","12",give9,give10,give11,give12,".addpayInfoThree",".givemoney9",".givemoney10",".givemoney11",".givemoney12")
	
	
	var str1=""
	for(var i=0;i<newArr.length;i++){
		str1+="<li><img src='img/basicCircle.png' class='sure'/>"+newArr[i]+"</li>";
	}
	$(".AIC").append(str1)
	var txts="";
	for(var i=0;i<dkBank.length;i++){
		txts+="<li><img src='img/yuan.png'/><span>"+dkBank[i]+"</span></li>";
	}
	$(".moneyMeans").append(txts)
	
	var backInfo={
		"工商北京分行":"0",
		"工商攀枝花分行":"1",
		"工商河北分行":"2",
		"招商北京分行":"3",
		"招商攀枝花分行":"0",
		"招商河北分行":"0",
		"建行攀枝花分行":"0",
		"建行北京分行":"0",
		"建行河北分行":"0",
	}
	
	
	$(".canChange").attr("readonly",true)
	
})

//隐藏项目信息
function hideInformation(a,b,c,d,e){
	a.click(function(){
		if(b.attr("src")==d){
			b.attr("src",e);
			c.slideDown("slow")
		}else{
			b.attr("src",d);
			c.slideUp("slow")
		}
	})
}

//隐藏人数
function hidePeople(){
	$(".account").click(function(){
		if($(".account").css("width")=="90px"){
			$(".account").css("width","156px")
			$(".hidePeople").show("slow")
		}else{
			$(".account").css("width","90px")
			$(".hidePeople").hide("fast")
		}
	})
}


//添加贷款行

function addLoan(){
	$("#addLoan").click(function(){
		$(".savemask").show()
		funShowDivCenter($(".savemaskContent"))
		
	})
	
}

//取消贷款行
function cancle(){
	$("#cancle").click(function(){
		$(".savemask").hide()
	})
}




$(document).ready(function(){
	$("#date option").flatpickr()
})


function dateFocus(){
	$(".edit").click(function(){
		$(".flatpickr-calendar").eq(1).toggleClass("open")
		$(".flatpickr-calendar").eq(1).attr("style","top: 729px; left: 527px;")
	})
}

//提交 贷款行
//将值存在数组中(银行)
var newArr=[];
//贷款方式 
var dkBank=[];
var arr=[];
var kk=0;
function submitBack(){
	
	$("#addBack").click(function(){
		
		//银行和支行输入为空的话提示输入
		
		if($("#choiceBack").val()==""||$("#other").val()==""){
			alert("请添加贷款行");
			return;
		}
		
		
		
		var str="<li data-index='"+kk+"'><img src='img/basicCircle.png' class='sure'/><span>"+$("#choiceBack").val()+''+$("#other").val()+"</span><img src='img/edit.jpg' class='sure amend'/></li>";
		var moneyMeans="<li><img src='img/yuan.png'/><span>"+$("#means").val()+"</span></li>"
		$(".savemask").hide()
		
		kk++;
		var Lis=$(".AIC").children("li").length;
		//存值
		var bank=$("#choiceBack").val()+''+$("#other").val();
		if(kk==1){
			$(".startLeftOne").show();
			//计算时间
			$("#bStateOne").find(".editFirst").eq(0).show();
			$("#bStateTwo").find(".editFirst").eq(0).show();
			$("#bStateThree").find(".editFirst").eq(0).show();
			$("#bStateFour").find(".editFirst").eq(0).show()
			$(".bStateOne").children(".height").children("p").show();
		}else if(kk==2){
			$(".startLeftTwo").show();
			
			$("#bStateTwo").find(".editFirst").eq(0).show();
			$("#bStateThree").find(".editFirst").eq(0).show();
			$("#bStateFour").find(".editFirst").eq(0).show()
			$(".bStateTwo").children(".height").children("p").show();
			noStarting("#bStateOne")
		}else if(kk==3){
			$(".startLeftThree").show();
			$(".bStateThree").children(".height").children("p").show();
			$("#bStateOne").find(".editFirst").eq(0).show();
			$("#bStateTwo").find(".editFirst").eq(0).show();
			$("#bStateThree").find(".editFirst").eq(0).show();
			$("#bStateFour").find(".editFirst").eq(0).show()
			noStarting("#bStateOne")
			noStarting("#bStateTwo")
		}else if(kk==4){
			$(".startLeftFour").show();
			$(".bStateFour").children(".height").children("p").show();
			$("#bStateOne").find(".editFirst").eq(0).show();
			$("#bStateTwo").find(".editFirst").eq(0).show();
			$("#bStateThree").find(".editFirst").eq(0).show();
			$("#bStateFour").find(".editFirst").eq(0).show()
			noStarting("#bStateOne")
			noStarting("#bStateTwo")
			noStarting("#bStateThree")
		}
		
		$(".effect").css("display","block")
		$("#arrow img").attr("src","img/arrows.png")
		if(Lis<=4){
			arr.push(bank)
			$(".AIC").append(str);
			$(".moneyMeans").append(moneyMeans);
			if(Lis==4){
				
				$(".blueBorder").hide()
			}
		}
		amendBank()
		$("#choiceBack").val("");
		$("#other").val("")
	})
	
}

//隐藏设置时间

function timeCancle(){
	$("#timeCancle").click(function(){
		$(".setTime").hide()
	})
}

//显示设置时间   开始时间 结束时间 每一个结束时间是下一个开始时间
function edit(){
	var stateTxt="";
	var statImg="";
	var inputTxt="";
	var choiceState="";
	var flag=0;
	var startTs="";
	var endTE="";
	var firstImg="";
	var parentIndex="";
	var parentsIndex="";
	var sumDay="";
	var startTime="";
	var endTime="";
	//每个模块共多少天
	var total="";
	//第个模块逾期多少天
	var excess="";
	var limit="";
	var limitIndex="";
	//预期时间
	var exTime="";
	//阶段性项目完成需要多少天
	var needDay=0;
	var needText="";
	var stop=""
	var toDay="";
	var length="";
	$(".editFirst").off().on('click',function(){
		firstImg=$(this);
		//开始时间   用来做判断当前点击是开始时间还是结束时间
		stateTxt=$(this).prevAll("span").text();
		
		//状态图片
		stateImg=$(this).parent().parent().prev().children("img");
		//状态文字 
		choiceState=$(this).parent().parent().prev().children("p");
		//开始时间信息
		inputTxt=$(this).parent().children("input");
		//下一个开始时间
		startTs=$(this).parents(".startState").next().find(".STart");
		//结束时间
		endTE=$(this).parent().next().children("input");
		if(stateTxt=="开始时间："){
			$("#startT").show();
			$("#endHide").show();
			flag=1;
		}else{
			$("#endHide").show();
			$("#startT").hide();
			flag=2;
		}
		$(".setTime").show();
		funShowDivCenter($(".settimeContent"))
		$("#submit").off().on('click',function(){
			if($("#getStarts").val()==""||$("#getEnds").val()==""){
				alert("请选择时间");
				return;
			}
			parentsIndex=firstImg.parents(".backState").children(".height");
			
			stop=$("#choiceState").val();
			if(stop=="进行中"){
				//进行中图片
				stateImg.attr("src","img/ing.jpg")
				//进行中文字颜色
				choiceState.addClass("ingColor")
				parentsIndex.html("<img src='img/completeRemind.png'/>进行中");
			}else if(stop=="已停止"){
				//停止中的图片
				stateImg.attr("src","img/stop.png")
				firstImg.hide();
			}else{
				//已完成图片
				stateImg.attr("src","img/complete.png")
				//移除进行中文字颜色
				choiceState.removeClass("ingColor")
				//添加已完成文字颜色
				choiceState.addClass("completeColor")
				//上一个已完成的状态，打开下一个可编辑状态
			   startTs.parent().next().children("img").css("display","inline-block");
				//已完成的状态下，不能再编辑
				
				firstImg.hide();
				//计算每个模块需要多少天
				parentsIndex.html("<img src='img/completeRemind.png'/><span>进行中</span>")
				
			}
			if(flag==1){
				inputTxt.val($("#getStarts").val())
				endTE.val($("#getEnds").val())
				startTs.val(endTE.val())
				choiceState.text($("#choiceState").val());
				if(choiceState.text()=="已停止"){
					stopped(".bStateOne");
					stopped(".bStateTwo");
					stopped(".bStateThree");
					stopped(".bStateFour");
				}
				startTime=new Date(firstImg.prev().val());
				endTime=new Date(firstImg.parent().next().children(".lognote").val())
				//时间差
				timeDif=(endTime.getTime()-startTime.getTime())/(24*3600*1000);
				
				total=firstImg.parents(".changeImg ").siblings(".F12").children(".days");
				total.text(timeDif);
				
				
				//每一个日期的逾期
				limit=firstImg.parents(".startRight").children(".F12").children(".Red12");
				limitIndex=firstImg.parents(".startState").index();
				
				//预期时间
				exTime=firstImg.parents(".backState").siblings(".percentBox").children(".percent").eq(limitIndex).find(".choiceDT");
				needDay+=Number(firstImg.parents(".startRight").find(".days").text());
				if(exTime.text()-timeDif<0){
					limit.text("逾期"+String(exTime.text()-timeDif).substr(1)+"天");
				}else{
					limit.text("逾期0天")
				}
			}else if(flag==2){
				inputTxt.val($("#getEnds").val())
				choiceState.text($("#choiceState").val())
				if(choiceState.text()=="已停止"){
					stopped(".bStateOne");
					stopped(".bStateTwo");
					stopped(".bStateThree");
					stopped(".bStateFour");
				}
				startTs.val($("#getEnds").val())
				//开始时间
				startTime=new Date(firstImg.parent().prev().children(".STart").val())
				
				//结束时间
				endTime=new Date(firstImg.prev().val());
				//时间差
				timeDif=(endTime.getTime()-startTime.getTime())/(24*3600*1000);
				total=firstImg.parents(".changeImg ").siblings(".F12").children(".days");
				total.text(timeDif);
				length=firstImg.parents(".backState").children(".startState").length;
				sumDay=firstImg.parents(".backState").children(".startState").eq(length-2).find(".noStart");
				
				//判断最后一个状态是否完成到下一个阶段
				needDay+=Number(firstImg.parents(".startRight").find(".days").text());
				if(sumDay.text()=="已完成"){
					if(sumDay.parents(".effect").prev(".changeMargin").find(".fl").text()=="准入评级"){
						needDay=20-needDay;
						//console.log(needDay)
						if(needDay>=0){
							parentsIndex.html("<img src='img/completeRemind.png'/><span>实际完成时间20天</span><span class='rd'>提前"+needDay+"天</span>");
						}else{
							parentsIndex.html("<img src='img/stopRemind.png'/><span>实际完成时间20天</span><span class='rd1'>逾期"+String(needDay).substr(1)+"天</span>");
						}
						//下一阶段的开始的值是上一阶段结束的值 
						$(".effectTwo").find(".STart").eq(0).val($(".effect").find(".bStateOne .startState").eq(2).find(".lognote").val());
						$(".effectTwo .bStateTwo .startState").find(".STart").eq(0).val($(".effect").find(".bStateTwo .startState").eq(2).find(".lognote").val());
						$(".effectTwo .bStateThree .startState").find(".STart").eq(0).val($(".effect").find(".bStateThree .startState").eq(2).find(".lognote").val());
						$(".effectTwo .bStateFour .startState").find(".STart").eq(0).val($(".effect").find(".bStateFour .startState").eq(2).find(".lognote").val());
						//$(".effectTwo").find(".bStateTwo").find(".startState").eq(0).find(".editFirst").eq(1).show()
						//$(".effectTwo").find(".bStateThree").find(".startState").eq(0).find(".editFirst").eq(1).show()
						//$(".effectTwo").find(".bStateFour").find(".startState").eq(0).find(".editFirst").eq(1).show()
						//$(".effectTwo").find(".bStateOne").find(".startState").eq(0).find(".editFirst").eq(1).show();
						com(".effect .bStateOne",".effectTwo .bStateOne")
						com(".effect .bStateTwo",".effectTwo .bStateTwo")
						com(".effect .bStateThree",".effectTwo .bStateThree")
						com(".effect .bStateFour",".effectTwo .bStateFour")
						$(".arrowTwo img").attr("src","img/arrows.png");
						$(".sign").eq(0).removeClass("sign");
						$(".effectTwo").show();
						$(".times").css("left","29%");
						needDay=0;
					}else if(sumDay.parents(".effectTwo").prev(".changeMargin").find(".fl").text()=="项目评估"){
							
						needDay=90-needDay;
						if(needDay>=0){
							
							parentsIndex.html("<img src='img/completeRemind.png'/><span>实际完成时间90天</span><span class='rd'>提前"+needDay+"天</span>");
						}else{
							parentsIndex.html("<img src='img/stopRemind.png'/><span>实际完成时间90天</span><span class='rd1'>逾期"+String(needDay).substr(1)+"天</span>");
						}
						$(".arrowThree img").attr("src","img/arrows.png");
						$(".sign").eq(0).removeClass("sign");
						$(".effectThree").show();
						$(".times").css("left","49%");
						needDay=0;
						com(".effectTwo .bStateOne",".effectThree .bStateOne")
						com(".effectTwo .bStateTwo",".effectThree .bStateTwo")
						com(".effectTwo .bStateThree",".effectThree .bStateThree")
						com(".effectTwo .bStateFour",".effectThree .bStateFour")
						
						$(".effectThree").find(".STart").eq(0).val($(".effectTwo").find(".bStateOne .startState").eq(5).find(".lognote").val());
						$(".effectThree .bStateTwo .startState").find(".STart").eq(0).val($(".effectTwo").find(".bStateTwo .startState").eq(5).find(".lognote").val());
						$(".effectThree .bStateThree .startState").find(".STart").eq(0).val($(".effectTwo").find(".bStateThree .startState").eq(5).find(".lognote").val());
						$(".effectThree .bStateFour .startState").find(".STart").eq(0).val($(".effectTwo").find(".bStateFour .startState").eq(5).find(".lognote").val());
					}else if(sumDay.parents(".effectThree").prev(".changeMargin").find(".fl").text()=="合同签署"){
						needDay=20-needDay;
						if(needDay>=0){
							
							parentsIndex.html("<img src='img/completeRemind.png'/><span>实际完成时间20天</span><span class='rd'>提前"+needDay+"天</span>");
						}else{
							parentsIndex.html("<img src='img/stopRemind.png'/><span>实际完成时间20天</span><span class='rd1'>逾期"+String(needDay).substr(1)+"天</span>");
						}
						$(".arrowFour img").attr("src","img/arrows.png");
						$(".sign").eq(0).removeClass("sign");
						$(".effectFour").show();
						$(".times").css("left","69%");
						needDay=0;
					}
					
				}
				
				//每一个日期的逾期
				limit=firstImg.parents(".startRight").children(".F12").children(".Red12");
				limitIndex=firstImg.parents(".startState").index();
				
				//预期时间
				exTime=firstImg.parents(".backState").siblings(".percentBox").children(".percent").eq(limitIndex).find("span");
				if(exTime.text()-timeDif<0){
					limit.text("逾期"+String(exTime.text()-timeDif).substr(1)+"天");
				}else{
					limit.text("逾期0天")
				}
			}
			$(".setTime").hide();
		})
		
	})
	
	
		
}



//日志部分

function blog(){
	//显示日志
	var blogStr="";
	//日志数量
	var blogNum=""
	$(".addtoBlog").html("");
	//点击日志
	$(".four").off().on("click",function(){
		$(".historyBlogmask").show();
		//console.log("dddddddd")
		//日志显示在可视窗口中间
		funShowDivCenter($(".historyBlogContent"))
		if($(".addtoBlog").children(".blogCon").length>0){
			$(".addBorder").show()
			$(".historyBlogContent").css("height","450px")
		}else{
			$(".historyBlogContent").css("height","350px")
		}
		blogNum=$(this).children(".hisNum");
		//删除日志
		$(".delBlog").off().on("click",function(){
			$(this).parents(".blogCon").remove()
			blogNum.text(Number(blogNum.text())-1);
			if($(".addtoBlog").children(".blogCon").length<=0){
				$(".addBorder").hide();
				$(".historyBlogContent").css("height","350px")
			}
		})
	})
	
	//取消日志
	$("#historyDel").click(function(){
		$(".historyBlogmask").hide();
	})
	//添加日志
	$("#historySure").click(function(){
		if($("#hisblogDate").val()==""){
			alert("请选择日期");
			return;
		}
		if($("#blogTxt").val()==""){
			alert("请输入内容");
			return;
		}
		var d=new Date();
		blogStr=`<div class="blogCon">
		<div class="historyCon">
		<div class="blogDate">${$('#blogTxt').val()}</div>
					</div>
					<div class="historyInfo">
						时间：<span class="createTime">${$("#hisblogDate").val()+" "+d.getHours()+":"+d.getMinutes()}</span>创建人：<span class="creater">宁琳</span>
						<span class="delBlog"><img src="img/del.jpg" class="delInfo"/><span>删除</span></span>
					</div>
			</div>`
				$(".addtoBlog").append(blogStr);
				blogNum.text(Number(blogNum.text())+1);
				$("#blogTxt").val("");
				$(".historyBlogmask").hide();
	})
	
	
		
		
}







//取消日志

/*function blogDel(){
	$("#blogDel").click(function(){
		$(".blogmask").hide();
	})
}
*/


//修改银行
var liIndex=""
function amendBank(){
	
	$(".amend").off().on("click",function(){
		$(".changeBackmask").show()
		liIndex=parseInt($(this).parent("li").attr("data-index"));
			$("#subBack").off().on("click",function(){
			$(".changeBackmask").hide();
			//修改银行信息
			var txt=$("#amendBack").val()+''+$("#otherAmendBack").val();
			$(".AIC").children("li").eq(liIndex+1).children("span").text(txt);
			//修改贷款模式信息
			$(".moneyMeans").children("li").eq(liIndex+1).children("span").text($("#changeMeans").val())
		})
	})
}

//取消修改银行
function cancleAmend(){
	$("#changeCancle").click(function(){
		$(".changeBackmask").hide()
	})
}

//审批进度和资料库切换

function tabs(){
	$(".tabChange").click(function(){
		$(this).addClass("Active");
		$(this).siblings().removeClass("Active")
		$(".tabSH").hide()
		$(".tabSH").eq($(this).index()).show()
	})
}

//必备资料和其他资料切换
function requireInfo(){
	$(".TAB").click(function(){
		$(this).addClass("actives");
		$(this).siblings().removeClass("actives")
		$(".infos").hide()
		$(".infos").eq($(this).index()).show()
	})
}

//其他上传和取消上传资料、提交资料

function upLoad(){
	var f=new Date();
	var dateStr=f.getFullYear()+"-"+(f.getMonth()+1)+"-"+f.getDate()+" "+f.getHours()+":"+f.getMinutes()
	$(".bbupload").off().on("click",function(){
		$(".uploadInfo").show();
		funShowDivCenter($(".uploadInfoContent"))
		$("#addUpload").off().on("click",function(){
			var zl=$("#infoName").val();
			var zls=$("#choiceType").val();
			$(".uploadInfo").hide();
			var trs=`
			<tr>
	        <td>${zl}</td>
	        <td>${zls}</td>
	        <td>ben</td>
	        <td><span>${dateStr}</span></td>
	        <td class="fit">
	        	<img src="img/revise.png"><span>下载</span>
	        	<img src="img/del.png"><span class="delTr">删除</span>
	        </td>
	      </tr>`
			$(".mustInfo tbody").append(trs);
	      	
	      	delTr()
	      	changeColor()
		})
	})
	$("#cancleUpload").click(function(){
		$(".uploadInfo").hide()
	})
	
}
//必备资料

function mustUpLoad(){
	funShowDivCenter($(".uploadInfoContent"))
	$(".upload").off().on("click",function(){
		
		$(".uploadInfo").show();
		$("#addUpload").off().on("click",function(){
			var zl=$("#infoName").val();
			var zls=$("#choiceType").val();

			$(".uploadInfo").hide();
			//console.log($("#choiceType").val())
			var trs=`
			<tr>
	        <td>${zl}</td>
	        <td>${zls}</td>
	        <td>ben</td>
	        <td><span></span></td>
	        <td class="fit">
	        	<img src="img/revise.png"><span>下载</span>
	        	<img src="img/del.png"><span class="delTr">删除</span>
	        </td>
	      </tr>`
	      //console.log("aaaaaaaaaaaaaaaa")
			$(".otherInfos tbody").append(trs);
	      	
	      	
	      delTr()
	      	changeColor()
		})
	})
	$("#cancleUpload").click(function(){
		$(".uploadInfo").hide()
	})
}

//其他资料

function otherUpLoad(){
	$(".upload").click(function(){
		$(".uploadInfo").show()
	})
	$("#cancleUpload").click(function(){
		$(".uploadInfo").hide()
	})
	$("#addUpload").click(function(){
		$(".uploadInfo").hide()
	})
}

//删除资料
function delTr(){
	$(".delTr").click(function(){
		$(this).parent().parent().remove();
		changeColor();
	})
}

//删除文件

function delFile(){
	$(".delFile").click(function(){
		$(this).parents(".delete").remove()
	})
}

//隔行变色

function changeColor(){
	$(".infos tr").removeClass("bjBlue");
	$(".infos tr").removeClass("lightBlue");
	$(".infos tr:nth-child(odd)").addClass("bjBlue");
	$(".infos tr:nth-child(even)").addClass("lightBlue");
}

//修改信息(数据)

function correctInfo(){
	$(".startDay").flatpickr();
	$(".grid").flatpickr();
	$(".startDay").attr("disabled",true);
	$(".grid").attr("disabled",true);
	$(".correctInfo").click(function(){
		if($(".correctInfo span").text()=="保存信息"){
			$(".correctInfo span").text("修改信息");
			$("input").attr("readonly",true);
			$(".canChange").attr("style","");
			$(".startDay").attr("disabled",true);
			$(".grid").attr("disabled",true);
		}else{
			$(".correctInfo span").text("保存信息");
			$(".canChange").attr("style","background:white;")
			$(".canChange").attr("readonly",false);
			$(".startDay").attr("disabled",false);
			$(".grid").attr("disabled",false);
		}
		
		
	})
	
	$(".canChange").attr("readonly",false);
}






//合同修改信息

function changeCInfo(){
	 $("#brokerage").flatpickr();
		$("#guaranty").flatpickr();
		$("#before").flatpickr();
		 $("#brokerage").attr("disabled",true);
		   $("#guaranty").attr("disabled",true);
			$("#before").attr("disabled",true);
	   $(".canChange1").attr("readonly",true)
	   $(".changePact").click(function(){
		   $(".canChange1").attr("style","background:white")
		   if($(this).text()=="修改信息"){
			   $(".arrowTop").attr("style","display:block")
			   //$(".canChange1").attr("readonly",false)
			   $(this).text("保存信息");
			   $("#brokerage").attr("disabled",false);
			   $("#guaranty").attr("disabled",false);
				$("#before").attr("disabled",false);
				$(".canChange1").attr("readonly",false)
		   }else{
			   $(this).text("修改信息")
			   $(".canChange1").attr("readonly",true)
			   $(".canChange1").attr("style","")
			   $("#brokerage").attr("disabled",true);
			   $("#guaranty").attr("disabled",true);
				$("#before").attr("disabled",true);
		   }
		   //$(".canChange1").attr("readonly",true)
		   $(".arrowTop").attr("style","display:none")
	   })
	   $(".arrowTop").attr("style","display:none !important")
	   
}








//让指定的遮罩层始终显示在屏幕正中间
   function funShowDivCenter(div) {
      var top = ($(window).height() - div.height()) / 2;
      var left = ($(window).width() - div.width()) / 2;
      var scrollTop = $(document).scrollTop();
      var scrollLeft = $(document).scrollLeft();
      div.css({ position: 'absolute', 'top': top + scrollTop, left: left + scrollLeft }).show();
   }
   
   
   function stopped(div){
	   for(var i=0;i<$(""+div+" .noStart").length;i++){
			if($(""+div+" .noStart")[i].innerHTML=="已停止"){
				$(""+div+" .noStart:gt("+i+")").text("已停止");
				$(""+div+" .stopped:gt("+i+")").attr("src","img/stop.png");
				$(""+div+" .editFirst").hide();
			}
		}
	   for(var j=0;j<$(""+div+" .height").length;j++){
		   if($(""+div+" .height").eq(j).prev(".startState").find(".noStart").text()=="已停止"){
			   $(""+div+" .height").eq(j).html("<img src='img/stopRemind.png'/><span>已停止</span>")
		   }
			
		}
	   
   }
   
   
   //未开始的状态
   
   function noStarting(div){
	   if($(""+div+" .startState").eq(0).find(".noStart").text()=="未开始"){
			$(div).find(".editFirst").eq(0).show();
		}else{
			$(div).find(".editFirst").eq(0).hide();
		}
   }
   
   //判断是否显示已完成状态，显示下一个结束时间图片 准入评级--项目评估
 //判断是否显示已完成状态，显示下一个结束时间图片 项目评估--合同签署
   function com(div,div1){
	  if($(div).children(".startState").eq(2).find(".noStart").text()=="已完成"){
		  $(div1).children(".startState").eq(0).find(".editFirst").eq(1).show();
		  if($(div1).children(".startState").eq(0).find(".noStart").text()=="已完成")
			  $(div1).children(".startState").eq(0).find(".editFirst").eq(1).hide()
	  }
   }
   
 //判断是否显示已完成状态，显示下一个结束时间图片 项目评估--合同签署
   function com1(div,div1){
		  if($(div).children(".startState").eq(5).find(".noStart").text()=="已完成"){
			  $(div1).children(".startState").eq(0).find(".editFirst").eq(1).show();
			  if($(div1).children(".startState").eq(0).find(".noStart").text()=="已完成")
				  $(div1).children(".startState").eq(0).find(".editFirst").eq(1).hide()
		  }
	   }
   
   
   
   //合同信息收起来
   
   function sshow(){
	   $(".compactArrow").click(function(){
		   //console.log("ddddddddd")
		   if($(this).children("img").attr("src")=="img/up.png"){
			 //  console.log("ddddddddd")
			   $(this).children("img").attr("src","img/down.png")
			   $(".SShow").slideUp("slow");
			   
		   }else{
			   $(".SShow").slideDown("slow");
			   $(this).children("img").attr("src","img/up.png")
		   }
	   })
   }
   
   
   
   

   
   
   
   
   
   
   
   
   
   //放款进度
   
   function fkShow(div1,div2){
	   $(div1).click(function(){
		   if($(div1).attr("src")=="img/fkup.png"){
			   $(div1).attr("src","img/fkdown.png")
			   $(div2).slideDown("slow");
		   }else{
			   $(div1).attr("src","img/fkup.png");
			   $(div2).slideUp("slow")
		   }
		   
		   
	   })
   }
 //添加放款
   
   function addSloan(){
	   $(".addSloan").click(function(){
		   $(".addloanMask").show();
		   funShowDivCenter($(".addloanContent"));
	   })
	   $(".addloanCancle").click(function(){
			    $(".addloanMask").hide();
		   })
	  $(".addloanSubmit").click(function(){
		  if($("#giveNum").val()=="请选择"||$("#LendingTime").val()==""||$("#loanMoney").val()==""){
			  alert("请输入信息");
			  return;
		  }
		  loanMoneys=Number($("#loanMoney").val())
		  totalMoney=loanMoneys;
		  $(".addloanMask").hide();
		  if($("#giveNum").val()==1||$("#giveNum").val()==2||$("#giveNum").val()==3||$("#giveNum").val()==4){
			  addeveryLoan(".fk"+$("#giveNum").val())
			  $(".pleaseChoice").attr("selected",false)
		  }else if($("#giveNum").val()==5||$("#giveNum").val()==6||$("#giveNum").val()==7||$("#giveNum").val()==8){
			  $(".loanTwo").show();
			  $(".givePlanTwo").show()
			  addeveryLoan(".fk"+$("#giveNum").val())
			   $(".pleaseChoice").attr("selected",false)
		  }else{
			  $(".loanThree").show();
			  addeveryLoan(".fk"+$("#giveNum").val())
			   $(".pleaseChoice").attr("selected",false)
		  }
		  
		  
		  $(".pleaseChoice").attr("selected",true)
		  $("#loanMoney").val("");
		  $("#LendingTime").val("")
	  })
   }
   //添加放款信息
   function addeveryLoan(div1){
	   $(div1).eq(0).text("第"+$("#giveNum").val()+"笔")
		  $(div1).eq(1).text($("#loanMoney").val())
		  $(div1).eq(2).text($("#LendingTime").val())
   }
   //放款进度-合同付款管理-添加供应商
   function supplier(){
	   $("#addManger").click(function(){
		   if($(this).text()=="添加信息"){
			   $(this).text("保存信息")
			  // totalMoney=loanMoneys;
			   //console.log(totalMoneys)
			   var addTr=document.getElementsByClassName("addTR")[0];
			   var tr=document.createElement("tr");
			   for(var i=0;i<7;i++){
				   var td=document.createElement("td");
				   if(i<1){
					   td.innerHTML="<input type='text' name='' id='' value='"+suppliers+"' class='fl companyInfo' readonly='readonly'/>"
				   }else if(i==1){
					   td.innerHTML="<input type='text' name='' id='' value='"+loanMoneys+"' class='fl' readonly='readonly'/>"
				   }else if(i==2){
					   td.innerHTML="<input type='text' name='' id='' value='' class='fl htPrice'  placeholder='请输入'/>"
				   }else if(i==3){
					   td.innerHTML="<input type='text' name='' id='' value='0' class='fl already'  placeholder='请输入'/>"
				   }else if(i==4){
					   td.innerHTML="<input type='text' name='' id='' value='"+totalMoney+"' class='fl'  placeholder='请输入'/>"
				   }else if(i==5){
					   
					   td.innerHTML="<input type='text' name='' id='' value='' class='fl Nmoney'  placeholder='请输入'/>"
						   
				   }
				   tr.appendChild(td);
			   }
			   addTr.append(tr);
			   var gys=$(".fkShow").find("tr").length-1;
			   $(".htPrice").bind("input propertychange change",function(event){
				   $(".Nmoney").eq(gys).val(Number($(".htPrice").eq(gys).val())-purpuses)
			   })
			   
			   
		   }else{
			   $(this).text("添加信息");
			   $(".addTR").find("select").attr("disabled",true)
			   $('.addTR').find("input").attr("readonly",true)
		   }
		  
	   })
   }
   
   
   //添加放款用途
   
   //放款用途提交
   //第1笔到第4笔的用途
   //.addUsesone:添加放款用途的每个按钮,  .addMake:每4笔的放款用途    use1,use2,use3,use4,变量++,".use1"
   //dd1,dd2,dd3,dd4选择第几笔,".use2",".use3",".use4",共几项用途
   //oneToFour(".addUsesTwo",".addMake1",".use5",".use6",".use7",".use8",use5,use6,use7,use8,"5","6","7","8")
   function oneToFour(div1,div2,div3,div4,div5,div6,use1,use2,use3,use4,dd1,dd2,dd3,dd4){

	    var suP=new Array(20);
	    //var suppliers1=new Array();
	    var companys;
	   // suppliers1=companys+1;
	    //suppliers1=new Array();
	    var ii={};
	   $(div1).off().on("click",function(){
		   funShowDivCenter($(".loanPurposeContent"))
		   $(".loanPurposeMask").show();
		   if(div1==".addUsesOne"){
			   //$("#company").bind("input propertychange change",function(event){
				//   console.log("ddddd")
				//   })
			   $("#loanPurposeNum option:gt("+4+")").attr("style","display:none");
			   $("#loanPurposeNum option:lt("+5+")").attr("style","display:block");
		   }else if(div1==".addUsesTwo"){
			   $("#loanPurposeNum option:lt("+5+")").attr("style","display:none");
		       $("#loanPurposeNum option:gt("+4+")").attr("style","display:block");  
		   	   $("#loanPurposeNum option:gt("+8+")").attr("style","display:none");
		   }else if(div1==".addUsesThree"){
			   $("#loanPurposeNum option:lt("+9+")").attr("style","display:none");
			   $("#loanPurposeNum option:gt("+8+")").attr("style","display:block");
		   	   }

		   $(".loanPurposeSubmit").off().on("click",function(){
			   if($("#loanPurposeNum").val()=="请选择"||$("#company").val()==""||$("#paymentMoney").val()==""){
					  alert("请输入信息");
					  return;
				  }
			   suppliers=$("#company").val();
			   companys=suppliers;

			   var suppliers1=[];
			   purpuses=Number($("#paymentMoney").val());
			   if(comms.indexOf($("#company").val())==-1){
					   comms.push($("#company").val()); 
						ii[suppliers]=purpuses;
			   }else{
					if(ii[suppliers].length==undefined){
						suppliers1.push(ii[suppliers],purpuses)
					}else{
						for(var cc=0;cc<ii[suppliers].length;cc++){
							suppliers1.push(ii[suppliers][cc])
						}
						suppliers1.push(purpuses)
					}
					ii[suppliers]=suppliers1
					console.log(ii)
					//console.log(ii["信息"])
			   }
			   if(comms.indexOf(suppliers)!=-1){
				 /*  if($("#loanPurposeNum").val()<2){
					   totalmoney=loanMoneys;
					   sumPurpuse=purpuses;
				   }else{*/
					   totalmoney+=loanMoneys;
					   $(".addTR").children("tr").eq(comms.indexOf(suppliers)).children("td").eq(1).children("input").val(loanMoneys);
					   $(".addTR").children("tr").eq(comms.indexOf(suppliers)).children("td").eq(4).children("input").val(totalmoney);
					   $(".addTR").children("tr").eq(comms.indexOf(suppliers)).children("td").eq(3).children("input").val(sumPurpuse);
					   sumPurpuse+=purpuses;
					   $(".addTR").children("tr").eq(comms.indexOf($("#company").val())).children("td").eq(5).children("input").val(Number($(".htPrice").eq($(".addTR").children("tr").length-1).val())-sumPurpuse)
				   //}
				}
			   var comPANY=$(".addTR").children("tr").eq(0).children("td").eq(0).find("input").val();
			   	for(var i=0;i<$(".mrLEFT").length;i++){
			   		if(comPANY==$(".mrLEFT").eq(i).text()){
				   		console.log(i);
				   		console.log($(".mrLEFT").eq(i+1).text())
			   		}
			   	}
			   
			   //console.log($(".addTR").children("tr").eq(0).children("td").eq(0).find("input").val())
			   $(".loanPurposeMask").hide()
			   if($("#").val()==dd1){

				   use1++;
				   if(showTR(div2+" .oneTfourFirst",use1)){
					   use1--
				   }
				   $(div3).text("共"+use1+"项");
				   $(".Selected").attr("selected",false);
			   }else if($("#").val()==dd2){
				   use2++;
				   if(showTR(div2+" .oneTfourTwo",use2)){
					   use2--
				   }
				   $(div4).text("共"+use2+"项");
				   $(".Selected").attr("selected",false);
			   }
			   else if($("#").val()==dd3){
				   	use3++;
				   if(showTR(div2+" .oneTfourThree",use3)){
					   use3--;
				   }
				   $(div5).text("共"+use3+"项");
				   $(".Selected").attr("selected",false);
			   }else if($("#").val()==dd4){
				   use4++;
				   if(showTR(div2+" .oneTfourFour",use4)){
					   use4--;
				   }
				   $(div6).text("共"+use4+"项");
				   $(".Selected").attr("selected",false);
			   }
			   $(".Selected").attr("selected",true);
			   $("#company").val("");
			   $("#paymentMoney").val("")
			   
		   })
	   })
	   $(".loanPurposeCancle").click(function(){
		   $(".loanPurposeMask").hide()
	   })
	   
   }
   
   
   
   //提交还款计划
   //d1,d2,d3,d3,当前选择的第几笔 kk1,kk2,kk3,kk4,变量,几笔还完,hh选择1-4笔的一个模块||5-8的一个模块
// subgivePlan("1","2","3","4",give1,give2,give3,give4,".addpayInfoOne",".givemoney1",".givemoney2",".givemoney3",".givemoney4")
   function subgivePlan(div,d1,d2,d3,d4,kk1,kk2,kk3,kk4,hh,div1,div2,div3,div4){

	   $(div).off().on("click",function(){
		   $(".payMask").show()
		   funShowDivCenter($(".payContent"))
		   if(div==".payingBtnOne"){
			   $("#paygiveNum option:gt("+4+")").attr("style","display:none");
			   $("#paygiveNum option:lt("+5+")").attr("style","display:block");
		   }else if(div==".payingBtnTwo"){
			   $("#paygiveNum option:lt("+5+")").attr("style","display:none");
		       $("#paygiveNum option:gt("+4+")").attr("style","display:block");  
		   	   $("#paygiveNum option:gt("+8+")").attr("style","display:none");
		   }else if(div==".payingBtnThree"){
			   $("#paygiveNum option:lt("+9+")").attr("style","display:none");
			   $("#paygiveNum option:gt("+8+")").attr("style","display:block");
		   } 
		   
		   $(".payingSubmit").off().on("click",function(){
			   if($("#paygiveNum").val()=="请选择"||$("#payingTime").val()==""||$("#payingMoney").val()==""){
					  alert("请输入信息");
					  return;
				  }
			   $(".payMask").hide()
		   
		   if($("#paygiveNum").val()==d1){
			   showgiveTR(hh+" .oneTfourFirst",kk1)
			   kk1++;
			   $(div1).text("共"+kk1+"项");
			   $(".canChoice").attr("selected",false)
		   }else if($("#paygiveNum").val()==d2){
			   showgiveTR(hh+" .oneTfourTwo",kk2)
			   kk2++;
			   $(div2).text("共"+kk2+"项")
			   $(".canChoice").attr("selected",false)
		   }else if($("#paygiveNum").val()==d3){
			   showgiveTR(hh+" .oneTfourThree",kk3)
			   kk3++;
			   $(div3).text("共"+kk3+"项")
			   $(".canChoice").attr("selected",false)
		   }else if($("#paygiveNum").val()==d4){
			   showgiveTR(hh+" .oneTfourFour",kk4)
			   kk4++
			   $(div4).text("共"+kk4+"项")
			   $(".canChoice").attr("selected",false)
		   }
		   $(".canChoice").attr("selected",true);
		   $("#payingTime").val("");
		   $("#payingMoney").val("")
		    //$(".payMask").hide();
	   })
	   })
	   $(".payingCancle").click(function(){
		   $(".payMask").hide()
	   })
   }
   
   
   
   
   //添加放款用途表格
   //添加还款计划表格
   function loanDetail(div){
	   var strs=`<tr class="">
				<td class="cenTER"></td>
				<td class="cenLeft oneTfourFirst"><span class="mrLEFT"></span><span class="mrLEFT"></span></td>
				<td class="cenLeft oneTfourTwo"><span class="mrLEFT"></span><span class="mrLEFT"></span></td>
				<td class="cenLeft oneTfourThree"><span class="mrLEFT"></span><span class="mrLEFT"></span></td>
				<td class="cenLeft oneTfourFour"><span class="mrLEFT"></span><span class="mrLEFT"></span></td>
			</tr>`
	   for(var i=0;i<5;i++){
		   $(div).append(strs);
		   $(div).children("tr").hide()
	   }
	   
   }
   
   //显示放款用途tr内容
   function showTR(div,dd){
	   for(var i=0;i<$(div).length;i++){
		   if($("#company").val()==$(div).eq(i).children("span").eq(0).text()){
			   alert("此供应商已存在");
			   return "biaoshi";
		   }
	   }
	   
	   $(div).eq(dd).parents("tr").show();
	   $(div).eq(dd).children("span").eq(0).text($("#company").val());
	   $(div).eq(dd).children("span").eq(1).text($("#paymentMoney").val());
   }
   
   
   //显示还款计划tr内容
   
   function showgiveTR(dd,use1){
	   $(dd).eq(use1).parents("tr").show();
	   $(dd).eq(use1).append("<span></span>")
	   $(dd).eq(use1).children("span").eq(0).text("第"+Number(use1+1)+"笔");
	   $(dd).eq(use1).children("span").eq(1).text($("#payingTime").val());
	   $(dd).eq(use1).children("span").eq(2).text($("#payingMoney").val());
   }
   //放款和还款模块的还款计划
   //添加还款计划
   
   